import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-06-02
 * Time: 16:13
 */
//实现一个简单的控制台版用户登陆程序, 程序启动提示用户输入用户名密码. 如果用户名密码出错, 使用自定义异常的方式来处理
public class User {
    private String name;
    private String number;
    private boolean zt=false;

     public User(String name,String number){
         this.name=name;
         this.number=number;
     }

    public int login()throws NameException,NumberException{
        Scanner scan=new Scanner(System.in);
         try{
             System.out.println("请输入用户名");
             String name=scan.nextLine();
             if(!this.name.equals(name)){
                 throw new NameException("用户名错误");
             }
             System.out.println("请输入密码");
             String number=scan.nextLine();
             if(!this.number.equals(number))
                 throw new NumberException("密码错误");
             this.zt=true;
             System.out.println("登陆成功");
             return 2;
         }
         catch(NameException ex){
             ex.printStackTrace();
             System.out.println("1.重新输入");
             System.out.println("0.退出系统");
             int n=scan.nextInt();
             return n;
         }
         catch(NumberException ex){
             ex.printStackTrace();
             System.out.println("1.重新输入");
             System.out.println("0.退出系统");
             int n=scan.nextInt();
             return n;
         }
    }

    public void isZt() {
        System.out.println("当前状态："+"用户 "+this.name+(this.zt?"已登录":" 未登录"));
    }
}
